package com.faxsun.core.catalog.service;

import javax.annotation.Resource;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.broadleafcommerce.common.persistence.EntityConfiguration;
import org.broadleafcommerce.common.util.TransactionUtils;
import org.broadleafcommerce.core.catalog.dao.ProductDao;
import org.broadleafcommerce.core.catalog.domain.Product;
import org.broadleafcommerce.core.catalog.domain.ProductAttribute;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.faxsun.core.catalog.dao.FSProductAttributeDao;

@Service("fsProductService")
public class FSProductServiceImpl implements FSProductService {

	@Resource(name = "blProductDao")
	ProductDao productDao;

	@Resource(name = "fsProductAttributeDao")
	FSProductAttributeDao productAttibuteDao;

	@Override
	@Transactional(value = TransactionUtils.DEFAULT_TRANSACTION_MANAGER)
	public Product saveProduct(Product product) {
		return productDao.save(product);
	}

	@Override
	public ProductAttribute createProductAttribute() {
		return productAttibuteDao.create();
	}

	@Override
	@Transactional(value = TransactionUtils.DEFAULT_TRANSACTION_MANAGER)
	public ProductAttribute saveProductAttribute(ProductAttribute productAttribute) {
		return productAttibuteDao.save(productAttribute);
	}

	@Override
	@Transactional(value = TransactionUtils.DEFAULT_TRANSACTION_MANAGER)
	public void removeProductAttribute(ProductAttribute productAttribute) {
		// FIXME: It is not working.
		productAttibuteDao.delete(productAttribute);
	}

}
